using System;
using System.ComponentModel;
using System.Windows.Input;

namespace WpfApplication1
{
    public class Context: INotifyPropertyChanged, IDataErrorInfo
    {
        public Context()
        {
            SimpleCommand = new RoutedCommand("asdf", typeof(Context));
            int a = 1;
        }

        private string _title;
        //dfsbgdafgdfgdfgdsfg
        public string Title
        {
            get { return _title; }
            set
            {
                if (_title != value)
                {
                    _title = value;
                    OnPropertyChanged("Title");
                }
            }
        }

        private string _buttonName;

        public string ButtonName
        {
            get { return _buttonName; }
            set
            {
                if (_buttonName != value)
                {
                    _buttonName = value;
                    OnPropertyChanged("ButtonName");
                }
            }
        }

        private bool _isBusy;

        public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                if (_isBusy != value)
                {
                    _isBusy = value;
                    OnPropertyChanged("IsBusy");
                }
            }
        }

        private string _textVal;

        public string TextVal
        {
            get { return _textVal; }
            set
            {
                if (_textVal != value)
                {
                    _textVal = value;
                    OnPropertyChanged("TextVal");
                }
            }
        }

        /// <summary>
        /// The SimpleCommand function.
        /// </summary>
        private void DoSimpleCommand()
        {
            //  Add a message.
            
        }

        public ICommand SimpleCommand { get; private set; }

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion

        #region Implementation of IDataErrorInfo

        public string Error
        {
            get
            {
                return this[string.Empty];
            }
        }

        public string this[string propertyName]
        {
            get
            {
                string result = string.Empty;
                propertyName = propertyName ?? string.Empty;
                if (propertyName == string.Empty || propertyName == "TextVal")
                {
                    if (string.IsNullOrEmpty(TextVal))
                    {
                        result = "Name cannot be blank!";
                    }
                }
                return result;
            }
        }

        #endregion
    }
}